n, k = map(int, input().split())
array = [int(x) for x in input().split()]

def find_min(l):
    min = float('inf')
    index = l

    for i in range(l, l + k):
        if array[i] <= m:
            m = array[i]
            p = i

    return min, index 

ans = 0
l = 0
while l + k <= n:
    min, index = find_min(l)

    if min:
        ans += min
        for i in range(l, l + k):
            array[i] -= min
            
    l = index + 1

ans += sum(array)           
print(ans)